package ils.web.util;

import ils.domain.issue.model.Issue;
import ils.domain.issue.model.Reserve;
import ils.web.model.MyIssue;
import ils.web.model.ReservationDetails;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: rejeevd
 * Date: 29/09/12
 * Time: 17:35
 * To change this template use File | Settings | File Templates.
 */
public class WebUtil
{
    public static final Logger logger = LoggerFactory.getLogger(WebUtil.class);

    public static List<MyIssue> convertToIssueDetails(List<Issue> issues)
    {
        List<MyIssue> myIssueList = new ArrayList<MyIssue>();
        try {
            for(Issue issue : issues)
            {
                MyIssue myIssue = new MyIssue();
                BeanUtils.copyProperties(myIssue, issue);
                myIssueList.add(myIssue);
            }
        } catch (Exception e) { logger.error("Exception during copying bean properties", e); }
        return myIssueList;
    }

    public static List<ReservationDetails> convertToReservationDetails(List<Reserve> reserves)
    {
        List<ReservationDetails> reservationDetailsList = new ArrayList<ReservationDetails>();
        try{
            for(Reserve reserve : reserves)
            {
                ReservationDetails reservationDetails = new ReservationDetails();
                BeanUtils.copyProperties(reservationDetails, reserve);
                reservationDetailsList.add(reservationDetails);
            }
        }catch (Exception e){ logger.error("Exception during copying bean properties", e); }
        return reservationDetailsList;
    }
}
